//
//  FucViewController.m
//  Clock
//
//  Created by NightElf_ZC on 16/4/25.
//  Copyright © 2016年 qianfeng. All rights reserved.
//

#import "FucViewController.h"
#import "ItemCell.h"
#import "BusRouteViewController.h"
#import "BusLineViewController.h"
#import "AboutViewController.h"
#import "RoundSearchViewController.h"

@interface FucViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView * collectionView;

@property (nonatomic, strong) NSArray * itemArray;

@end

@implementation FucViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"选择";
    self.view.backgroundColor = [UIColor whiteColor];
    
    _itemArray = @[@"周边检索",@"路径规划",@"公交查询",@"关于"];
    [self createView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self setUpNav];
}

- (void)setUpNav{
    
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]};
    /**
     * 添加左侧返回按钮
     */
    
    self.navigationController.navigationBar.translucent = YES;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"return"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem.tintColor=[UIColor blackColor];
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createView{
    
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH / 2 - 30, SCREEN_WIDTH / 2 - 60);
    flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    _collectionView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_collectionView];
    
    _collectionView.backgroundColor = [UIColor whiteColor];
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ItemCell * cell = [ItemCell cellWithCollectionView:collectionView andIndexPath:indexPath];
    cell.llabel.text = [_itemArray objectAtIndex:indexPath.row];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _itemArray.count;
}


- (CGFloat) collectionView:(UICollectionView *)collectionView
                    layout:(UICollectionViewLayout *)collectionViewLayout
minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 20;
}

- (CGFloat) collectionView:(UICollectionView *)collectionView
                    layout:(UICollectionViewLayout *)collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 20;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ItemCell * cell = (ItemCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.llabel.backgroundColor = [tool randomColor];
    
    switch (indexPath.row) {
        case 0:
        {
            RoundSearchViewController * rsvc = [[RoundSearchViewController alloc] init];
            [self.navigationController pushViewController:rsvc animated:YES];
            break;
        }
        case 1:
        {
            BusRouteViewController * brvc = [[BusRouteViewController alloc] init];
            [self.navigationController pushViewController:brvc animated:YES];
            break;
        }
        case 2:
        {
            BusLineViewController * blvc = [[BusLineViewController alloc] init];
            [self.navigationController pushViewController:blvc animated:YES];
            break;
        }
        case 3:
        {
            AboutViewController * avc = [[AboutViewController alloc] init];
            [self.navigationController pushViewController:avc animated:YES];
        }
            
        default:
            break;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
